<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateMessageTbl extends Migrator
{
    const TBL_NAME = 'message';
    const RELATED_TBL_NAME = 'user';


    public function change()
    {
        $table  =  $this->table(addTablePrefix(self::TBL_NAME),[
            'engine'=>'InnoDB',
            'comment' => '留言表',
            'signed' => false
        ]);

        $table
            ->addColumn('name', 'string',array('limit'  =>  17,'default'=>'','comment'=>'联系人'))
            ->addColumn('email', 'string',array('limit'  =>  64,'default'=>'','comment'=>'联系邮箱'))
            ->addColumn('title', 'string',array('limit'  =>  125,'default'=>'','comment'=>'标题'))
            ->addColumn('message', 'text',array('comment'=>'内容'))
            ->addColumn('visited', 'integer',array('signed' => false,'default'=>1,'comment'=>'是否查看(1 未查看, 2 已查看)'))
            ->addColumn('user_id', 'integer',array('signed' => false,'default'=>0,'comment'=>'用户'))
            ->addColumn('create_time', 'integer',array('signed' => false,'default'=>0,'comment'=>'创建时间'))
            ->addForeignKey('user_id',    addTablePrefix(self::RELATED_TBL_NAME), 'id', ['delete'=> 'CASCADE', 'update'=> 'NO_ACTION'])
            ->create();
    }
}
